﻿/*
Audica Uploader - application for convenient uploading to various file hostings
Copyright (C) 2011-2012 Makarov Andrey (Winand)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef UPLOADWORKER_H
#define UPLOADWORKER_H
#include <QObject>
#include <QNetworkReply>
#include <QtScript>
#include <QtScriptTools/QScriptEngineDebugger>
#include "scriptclasses.h"
#include "global.h"

class UploadWorker : public QObject
{
    Q_OBJECT
public:
    explicit UploadWorker(QString script, QObject* parent);
    void setPluginsList(QMap<QString, scriptplugin>* plugins);
    void upload(const QString filepath); //upload /filepath/ using /scriptPath/ script
protected:
    void timerEvent(QTimerEvent* event);
private:
    QMap<QString, scriptplugin>* scriptPlugins;
    QString scriptPath; //script for uploading
    QScriptEngine* engine;
    QScriptEngineDebugger debugger;
    int timerid;
public slots:
    QNetworkAccessManager* getAccessManager();
    void resetTimeout(int waittime);
    void finished_p(UploadResult* res);
signals:
    void progress(qint64 bytes, qint64 total);
    void setStatusText(const QString text);
    void finished(const QString filepath, UploadResult* res);
    void timeout();
};

#endif // UPLOADWORKER_H
